/*!
 ***************************************************************************
 *  \file complexmesh.cpp
 *  Using the StructuredMesh<> class with the NonUniform<> adaptor. 
 *  A little bit more complicated example of non-uniform mesh.
 *  A sine functor is used to define the point distribution in both
 *  sides of a rectangular domain.
 ***************************************************************************
 *  \author    Luis M. de la Cruz Salas [ Tue Dec 25 15:23:06 GMT 2010 ]
 ***************************************************************************
 */
 
#include <iostream>
#include <cmath>
#include "Meshes/StructuredMesh.hpp"
#include "Meshes/NonUniform.hpp"
#include "Utils/GNUplot.hpp"
using namespace Tuna;

class Sine {      
  double Amp;
  double Fre; 
public:                                    
  Sine(double a, double w) : Amp(a) { Fre = w * 0.5 * PI; }   
  
  double operator() (double epsi) {      
    return ( Amp * sin(Fre * epsi) ); 
  }
};

int main() 
{
    double length_x, length_y;
    int num_nodes_x, num_nodes_y;
    double amplitude1, frequency1;
    double amplitude2, frequency2;
    std::cout << "\n >---> Lenght x = ";
    std::cin >> length_x;
    std::cout << "\n >---> Lenght y = ";
    std::cin >> length_y;
    std::cout << "\n >---> Num of nodes x = ";
    std::cin >> num_nodes_x;
    std::cout << "\n >---> Num of nodes y = ";
    std::cin >> num_nodes_y;
    std::cout << "\n >---> Amplitude 1 = ";
    std::cin >> amplitude1;
    std::cout << "\n >---> Frequency 1 =";
    std::cin >> frequency1;
    std::cout << "\n >---> Amplitude 2 = ";
    std::cin >> amplitude2;
    std::cout << "\n >---> Frequency 2 =";
    std::cin >> frequency2;

// Reading data from the input file
/*
    std::ifstream input_cin ("input"); 
    input_cin >> length_x;
    input_cin >> length_y;
    input_cin >> length_z;
    input_cin >> num_nodes_x; 
    input_cin >> num_nodes_y; 
    input_cin >> num_nodes_z; 
    input_cin >> lambda;
    input_cin.close();
*/
    StructuredMesh<NonUniform<double, 2> > mesh_2D_C(length_x, num_nodes_x,
						     length_y, num_nodes_y);

    mesh_2D_C.calcPoints(X, Sine(amplitude1, frequency1));
    mesh_2D_C.calcPoints(Y, Sine(amplitude2, frequency2));
    mesh_2D_C.print();
    mesh_2D_C.writeToFile("./Data/mesh2DC");

#ifdef WITH_GNUPLOT
    GNUplot plotter;
    plotter("set view 0,0");
    plotter("splot \"./Data/mesh2DC\" w lp pt 7");
    std::cout << "\n >---> Press <1> and then <enter> to continue \n";
    int pause; std::cin >> pause;
#endif
  
    return 0;
}
